/**
 * 
 */
package cn.suse.android;


import cn.suse.android.entity.User;
import cn.suse.android.logic.UserParse;
import cn.suse.android.net.AppHelper;
import cn.suse.android.share.MainApplication;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * @author liubin
 * Create DateTime:Oct 26, 2012 2:05:32 PM
 * Description:
 * @Version: 1.0.0
 */
public class FriendActivity extends Activity {
	private String userId;
	private ImageView backImageView;
	private ImageView refershImageView;
	private ImageView userImageView;
	private ImageView genderImageView;
	private TextView userNameTextView;
	private Button editButton;
	private TextView homeTownTextView;
	private TextView statusTextView;
	private TextView cityTextView;
	private TextView interestTextView;
	private TextView introTextView;
	private TextView favBookTextView;
	private TextView favMovieTextView;
	private TextView favtTextView;
	private TextView idolTextView;
	private TextView mottoTextView;
	private TextView wishlistTextView;
	private Handler handler = new Handler(){
		public void handleMessage(android.os.Message msg) {
			User user = (User) msg.obj;
			MainApplication.bitmapManager.loadBitmap(user.getLogo50(), userImageView);
			if(user.getGender().equals("0")){
				genderImageView.setImageResource(R.drawable.widget_gender_man);
			}else{
				genderImageView.setImageResource(R.drawable.widget_gender_woman);
			}
			userNameTextView.setText(user.getName());
			editButton.setOnClickListener(listener);
			homeTownTextView.setText(user.getHometown());
			String statu = "";
			if(user.getStatus().equals("0")){
				statu = "其它";
			}else if(user.getStatus().equals("1")){
				statu = "学生";
			}else {
				statu = "已工作";
			}
			statusTextView.setText(statu);
			cityTextView.setText(user.getCity());
			interestTextView.setText(user.getInterest());
			favBookTextView.setText(user.getFavbook());
			favMovieTextView.setText(user.getFavmovie());
			favtTextView.setText(user.getFavmovie());
			idolTextView.setText(user.getIdol());
			mottoTextView.setText(user.getMotto());
			wishlistTextView.setText(user.getWishlist());
			introTextView.setText(user.getIntro());
		};
	};
	/* (non-Javadoc)
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		userId = (String) getIntent().getSerializableExtra("userId");
		setContentView(R.layout.user_info_detail);
		initFrame();
		loadFriendData();
		}
	private View.OnClickListener listener = new View.OnClickListener() {
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			
		}
	};
	private void initFrame() {
		// TODO Auto-generated method stub
		backImageView = (ImageView) findViewById(R.id.back);
		refershImageView = (ImageView) findViewById(R.id.user_info_refresh);
		userImageView = (ImageView) findViewById(R.id.user_info_userface);
		genderImageView = (ImageView) findViewById(R.id.user_info_gender);
		userNameTextView = (TextView) findViewById(R.id.user_info_username);
		editButton = (Button) findViewById(R.id.user_info_editer);
		homeTownTextView =(TextView)findViewById(R.id.hometown);
		statusTextView = (TextView)findViewById(R.id.status);
		cityTextView = (TextView)findViewById(R.id.city);
		interestTextView = (TextView)findViewById(R.id.interest);
		introTextView = (TextView)findViewById(R.id.intro);
		favBookTextView = (TextView)findViewById(R.id.favbook);
		favMovieTextView = (TextView)findViewById(R.id.favmovie);
		favtTextView = (TextView)findViewById(R.id.favtv);
		idolTextView = (TextView)findViewById(R.id.idol);
		mottoTextView = (TextView)findViewById(R.id.motto);
		wishlistTextView =(TextView)findViewById(R.id.wishlist);
	}
	private void loadFriendData(){
		new Thread(new Runnable() {
			
			@Override
			public void run() {
				Bundle bundle = User.getBundle();
				bundle.putString("uids", userId);
				String json = AppHelper.getFriendActive(MainActivity.instance.kaixin, FriendActivity.this, User.FRIEND_PATH, bundle, "GET");
				User user = new UserParse().parseData(json).get(0);
				Message message = new Message();
				message.obj = user;
				handler.sendMessage(message);
			}
		}).start();
	}
}
